//
//  MyOrderVC.m
//  digitalCurrency
//
//  Created by 小震GG on 2019/11/1.
//  Copyright © 2019 XinHuoKeJi. All rights reserved.
//

#import "MyOrderVC.h"
#import "MyOrderListCell.h"
#import "NewAllNetManager.h"
@interface MyOrderVC ()
@property (nonatomic, strong) NSMutableArray *dataArr;
@property (nonatomic, strong) LYEmptyView *emptyView;

@end

@implementation MyOrderVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.dataArr = [[NSMutableArray alloc]init];
        
    self.viewTitle.text = LocalizationKey(@"我的订单");
    [self.view addSubview:self.tableView];
    self.tableView.separatorColor = [UIColor clearColor];
       
    [self headRefreshWithScrollerView:self.tableView];
    
    [self loadData];
}

- (void)loadData{
 
    [NewAllNetManager myOrderList:@"1" pageSizeStr:@"50" CompleteHandle:^(id  _Nonnull resPonseObj, int code) {
       if (code) {
            NSInteger codeInt = [resPonseObj[@"code"] integerValue];
            if (codeInt == 0) {
                self.dataArr = [[NSMutableArray alloc]init];
                self.dataArr = resPonseObj[@"data"][@"list"];
               
                if (self.dataArr.count == 0) {
                    self.tableView.ly_emptyView = self.emptyView;
                }
            }
            else {
                [self.view makeToast:resPonseObj[MESSAGE] duration:1.5 position:CSToastPositionCenter];
            }
           [self.tableView reloadData];
        }
        else {
            [self.view makeToast:LocalizationKey(@"noNetworkStatus") duration:1.5 position:CSToastPositionCenter];
        }
    }];
}

#pragma mark-下拉刷新数据
- (void)refreshHeaderAction {
    [self loadData];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [[self dataArr] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

   MyOrderListCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"id"];
   if (cell == nil) {
       cell = [[MyOrderListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"id"];
   }
    
    NSDictionary *dataDic = self.dataArr[indexPath.row];
    [cell upDataModel:dataDic];
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 154;
}

- (LYEmptyView *)emptyView {
    if (!_emptyView) {
        _emptyView = [LYEmptyView emptyViewWithImageStr:@"emptyData" titleStr:[[ChangeLanguage bundle] localizedStringForKey:@"NoData" value:nil table:@"English"]];
        _emptyView.titleLabTextColor = tThreeColor;
        _emptyView.titleLabFont = [UIFont systemFontOfSize:19];
        _emptyView.contentViewY = SCREEN_HEIGHT/2.0-100;
    }
    return _emptyView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
